package com.olc.railing.busniess;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolExecutor {
    private ThreadPoolExecutor pool = null;

    private volatile static MyThreadPoolExecutor singleton;
    private MyThreadPoolExecutor (){}
    public static MyThreadPoolExecutor getMyThreadPoolInstance() {
        if (singleton == null) {
            synchronized (MyThreadPoolExecutor.class) {
                if (singleton == null) {
                    singleton = new MyThreadPoolExecutor();
                }
            }
        }
        return singleton;
    }

    public ExecutorService getMyThreadPoolExecutor() {
        if (pool == null) {
            pool = new ThreadPoolExecutor(
                    8,
                    9,
                    30,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(10),
                    new MyThreadFactory());
        }
        return this.pool;
    }

}
